package controleur;

import java.io.IOException;

import modele.Joueur;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import client.morpion.ProjetAndroidM2Activity;
import client.morpion.R;
import constructionChaine.Factory;

public class ControleurConnexion implements OnClickListener {

	private ProjetAndroidM2Activity activity;



	public ControleurConnexion(ProjetAndroidM2Activity activity) {
		super();
		this.activity = activity;
	}

	public void onClick(View arg0) {
		// TODO Auto-generated method stub

		try {
			EditText login = (EditText) activity.findViewById(R.id.login);
			EditText pass = (EditText) activity.findViewById(R.id.pass);
			if(login.getText().toString().trim().equals("")||pass.getText().toString().trim().equals(""))
			{
				activity.getToast().setText("Veuillez remplir tous les champs");
				activity.getToast().show();
			}
			else
			{
				activity.setJoueur(new Joueur(login.getText().toString(),pass.getText().toString()));
				activity.getOut().writeObject(activity.getJoueur());
				Object o = activity.getIn().readObject();
				Factory.getAction(activity).interagir(o);
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ProjetAndroidM2Activity getActivity() {
		return activity;
	}

	public void setActivity(ProjetAndroidM2Activity activity) {
		this.activity = activity;
	}



}
